export default {
	namespaced: true,
	state: () => ({
		address: JSON.parse(uni.getStorageSync('address') || '{}'),
		token: uni.getStorageSync('token') || '',
		userInfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
		history: '',
		openway: 'switchTab',
		TabList: [
			"/pages/home/home",
			"/pages/cate/cate",
			"/pages/cart/cart",
			"/pages/my/my"
		]
	}),
	mutations:{
		updateAddress(state, address){
			state.address = address
			this.commit('m_user/saveAddressToStorage')
		},
		saveAddressToStorage(state){
			uni.setStorageSync('address', JSON.stringify(state.address))
		},
		updateUserInfo(state, userInfoOBJ){
			state.userInfo = userInfoOBJ
			this.commit('m_user/saveUserToStorage')
		},
		saveUserToStorage(state){
			uni.setStorageSync('userInfo', JSON.stringify(state.userInfo))
		},
		updateToken(state, token){
			state.token = token
			this.commit('m_user/saveTokenToStorage')
		},
		saveTokenToStorage(state){
			uni.setStorageSync('token', state.token)
		},
		deleteUserInfo(state){
			this.commit('m_user/updateToken', '')
			this.commit('m_user/updateAddress', {})
			this.commit('m_user/updateUserInfo', {})
		},
		jumpTo(state, route){
			if(route.url) {
				state.openway = state.TabList.indexOf(route.url) === -1?"navigateTo":"switchTab"
				if(state.TabList.indexOf(route.url) === -1) uni.navigateTo({url: route.url})
				else uni.switchTab({url: route.url})
				state.history = route.from
			}
			if(!state.history && route === -1) uni.switchTab({url: '/pages/home/home'})
			if(route === -1 && state.history){
				if(state.openway === 'navigateTo') uni.navigateTo({url: state.history})
				else uni.switchTab({url: state.history})
				state.history = ''
			}
		}
	},
	ations:{},
	getters:{
		addressInfo(state){
			if(!state.address.provinceName) return ''
			return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
		}
	}
}